package org.yoao.moneymachine.business.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.yoao.crm.struts.form.NewsForm;
import org.yoao.crm.tools.TimeTool;
import org.yoao.moneymachine.bean.Bulletin;
import org.yoao.moneymachine.business.service.IBulletinService;
import org.yoao.moneymachine.dao.BulletinDAO;

/**
 * @author  Weishion.Yi
 * @description 
 * @date 2010-10-4 下午03:36:42
 */
public class BulletinServiceImpl implements IBulletinService {
	private BulletinDAO bulletinDAO = new BulletinDAO();
	
	@Override
	public void add(NewsForm form) throws Exception {
		Bulletin bulletin = new Bulletin();
		form.setCreateTime(TimeTool.getSystemTime());
		BeanUtils.copyProperties(bulletin, form);
		bulletinDAO.insert(bulletin);
	}

	@Override
	public void delete(String id) throws Exception {
		if(id.endsWith(",")) id = id.substring(0, id.length()-1);
		bulletinDAO.delete(id);
	}

	@Override
	public NewsForm getBulletin(String id) throws Exception {
		NewsForm form = new NewsForm();
		Bulletin bulletin = bulletinDAO.findById(id);
		BeanUtils.copyProperties(form, bulletin);
		return form;
	}

	@Override
	public int getDataCount(Map map) throws Exception {
		return bulletinDAO.getDataCount(map);
	}

	@Override
	public List view(int startRow, int endRow, Map map) throws Exception {
		return bulletinDAO.find(startRow, endRow, map);
	}

}
